<?php
set_time_limit(0);

class GmService extends ModuleGm
{
    /**
     * @var GmService
     */
    protected static $instance;

    /**
     * Get the instance of GameService.
     *
     * @return GmService
     */
    public static function get()
    {
        if (!self::$instance) {
            self::$instance = new GmService();
        }
        return self::$instance;
    }

    /**
     * Construction.
     */
    protected function __construct()
    {
        parent::__construct();
    }

    /**
     * get actor data
     *
     * @return array
     */
    public function getActor()
    {
        return ModulePrivilege::get()->getActor()->toArray();
    }

    /**
     * create a new player data
     *
     * @param int $platformId
     * @param string $platform default ModuleSnsConst::PFFB
     * @throws SzException 30606
     * @return boolean
     */
    public function createPlayer($platformId, $platform = ModuleSnsConst::PFFB)
    {
        $userId = ModuleSnsFactory::init(null, $platform)->portPlayerUserId($platformId, true);
        $profile = SzPersister::get()->getVo($userId, ModuleProfileConst::ORM_NAME_PROFILE);
        if ($profile) {
            throw new SzException(30606, null, ModuleGmConst::MODULE_NAME);
        }

        GameService::get()->createPlayerGameData($userId, $platformId);
        return true;
    }

    /**
     * Delete player game data.
     *
     * @param string $cacheColumnValue
     * @param string $cacheColumnName
     * @param boolean $onlyCache default false
     * @return boolean
     */
    public function deletePlayer($cacheColumnValue, $cacheColumnName = 'userId', $onlyCache = false)
    {
        if (empty($cacheColumnValue)) {
            return false; // userId错误，无法进行删除
        }

        if ($cacheColumnName == 'userId') {
            /** @var ModuleProfileVo $profile */
            $profile = SzPersister::get()->getVo($cacheColumnValue, ModuleProfileConst::ORM_NAME_PROFILE);
            if (!$profile) {
                return false; // 玩家数据并不存在，无法进行删除
            }
        }

        $ormNames = array();

        // 读取app的orm配置
        $appOrms = SzConfig::get()->loadAppConfig('orm');
        if ($appOrms) {
            foreach ($appOrms as $ormName => $ormSetting) {
                $ormNames[] = $ormName;
            }
        }

        // 读取各模块的orm配置
        $moduleNames = SzConfig::get()->loadAppConfig('app', 'MODULE_VERS');
        if ($moduleNames) {
            $moduleNames = array_keys($moduleNames); // array($moduleName => $version) => array($moduleName)
            foreach ($moduleNames as $moduleName) {
                if ($moduleName == 'module_privilege' || $moduleName == 'module_sns' || $moduleName == 'module_gm') {
                    /**
                     * module_sns 模块不需要删除，用户id不需要改变
                     * module_gm 模块并不属于游戏数据，不能在这里删除
                     * module_privilege 模块并不属于游戏数据，不能在这里删除
                     */
                    continue;
                }
                $moduleOrms = SzConfig::get()->loadModuleConfig($moduleName, 'orm');
                if (!$moduleOrms) {
                    continue;
                }
                foreach ($moduleOrms as $ormName => $ormSetting) {
                    $ormNames[] = $ormName;
                }
            }
        }

        foreach ($ormNames as $ormName) {
            $model = SzPersister::get()->getModel($ormName);
            if ($model->getColumnName($model->getCacheColumn()) != $cacheColumnName) {
                continue;
            }
            if ($model->hasListMode()) {
                if (is_null($model->getShardColumn())) {
                    $vos = $model->getListOfVoCache(null, $cacheColumnValue);
                } else {
                    $vos = $model->getListOfVoCache($cacheColumnValue, $cacheColumnValue);
                }
            } else {
                // 当没有数据时，为 null
                if (is_null($model->getShardColumn())) {
                    $vo = $model->getVoCache(null, $cacheColumnValue);
                } else {
                    $vo = $model->getVoCache($cacheColumnValue, $cacheColumnValue);
                }
                if ($vo) {
                    $vos = array($vo);
                } else {
                    $vos = array();
                }
            }
            if (!$vos) { // 该model数据不存在，不需要进行删除
                continue;
            }

            // 删除缓存数据
            if ($model->hasListMode()) {
                $model->deleteListOfVoCache($vos);
            } else {
                $model->deleteVoCache($vos[0]);
            }

            // 删除数据库数据
            if (!$onlyCache) {
                if ($model->getDbType() == SzAbstractDb::DB_TYPE_MYSQL) {
                    /* @var SzMySqlModel $model */
                    $model->delete($vos);
                } else if ($model->getDbType() == SzAbstractDb::DB_TYPE_REDIS) {
                    /* @var SzRedisModel $model */
                    $model->delete($vos);
                }
            }
        }

        if ($cacheColumnName == 'userId') {
            // 删除其它缓存
            foreach (json_decode(GameConst::CACHE_KEY_FOR_DELETE_USER, true) as $cacheKey) {
                SzContextFactory::get()->getAppCache($cacheColumnValue)->delete($cacheKey . $cacheColumnValue);
            }
        }

        if ($cacheColumnName == 'userId') {
            //获取当前用户所有的platformId
            $platformIdsInfo = SzContextFactory::get()->getDb()->select("SELECT `platformId` FROM `module_sns` WHERE `userId` = '{$cacheColumnValue}'");

            SzContextFactory::get()->getDb()->execute("DELETE FROM `module_sns`  WHERE `userId` = '{$cacheColumnValue}'");

            //清除对应的sns缓存
            foreach ($platformIdsInfo as $platformIdInfo) {
                SzCacheFactory::get()->getAppCache()->delete("ModuleSns:{$platformIdInfo['platformId']}");
            }
        }

        return true;
    }

    /**
     * Delete player game data cache.
     *
     * @param int $userId
     * @return boolean
     */
    public function deletePlayerCache($userId)
    {
        return $this->deletePlayer($userId, '', true);
    }

    /**
     * Get player data
     *
     * @param $userId
     * @throws SzException
     * @return array(
     *      ModuleProfileVo,
     *      ModuleProfileInfoVoList,
     *      ModulePaymentVo,
     * )
     */
    public function loadPlayerData($userId)
    {
        /**
         * @var ModuleProfileVo $profile
         * @var ModulePaymentVo $payment
         * @var ModuleProfileInfoVoList $profileInfoList
         */
        $profile = SzPersister::get()->getVo($userId, ModuleProfileConst::ORM_NAME_PROFILE);
        if (is_null($profile)) {
            throw new SzException(30606, null, ModuleGmConst::MODULE_NAME);
        }
        $payment = SzPersister::get()->getVo(null, ModulePaymentConst::ORM_NAME_PAYMENT, $userId);
        $profileInfoList = SzPersister::get()->getVoList($userId, ModuleProfileConst::ORM_NAME_PROFILE_INFO);

        return array($profile, $payment, $profileInfoList);
    }

    /**
     * update player user data via ormName
     *
     * @param int $userId
     * @param array $updateData
     * @return array
     */
    public function editPlayerData($userId, $updateData)
    {
        /** @var ModuleProfileVo $profile */
        $profile = SzPersister::get()->getVo($userId, ModuleProfileConst::ORM_NAME_PROFILE);
        if (SzUtility::checkArrayKey('profile', $updateData)) {
            foreach ($updateData['profile'] as $column => $value) {
                $this->setProperty($profile, $column, $value);
            }
            SzPersister::get()->setVo($profile);
        }

        /** @var ModulePaymentVo $payment */
        $payment = SzPersister::get()->getVo(null, ModulePaymentConst::ORM_NAME_PAYMENT, $userId);
        if (SzUtility::checkArrayKey('payment', $updateData)) {
            foreach ($updateData['payment'] as $column => $value) {
                $this->setProperty($payment, $column, $value);
            }
            SzPersister::get()->setVo($payment);
        }

        /**
         * @var ModuleProfileInfoVoList $profileInfoList
         * @var ModuleProfileInfoVo $profileInfo
         */
        $profileInfoList = SzPersister::get()->getVoList($userId, ModuleProfileConst::ORM_NAME_PROFILE_INFO);
        if (SzUtility::checkArrayKey('profileInfoList', $updateData)) {
            foreach ($updateData['profileInfoList'] as $infoType => $value) {
                $profileInfo = $profileInfoList->getElement($infoType, false);
                if ($profileInfo) {
                    $profileInfo->setInfo($value);
                    $profileInfoList->updateElement($infoType, $profileInfo);
                };
            }
            SzPersister::get()->setVoList($profileInfoList);
        }

        return array($profile, $payment, $profileInfoList);
    }

    /**
     * Set the value of "set{$columnName}".
     *
     * @param SzAbstractVo $vo
     * @param string $columnName
     * @param string $value
     * @return void
     */
    public function setProperty($vo, $columnName, $value)
    {
        if ($vo instanceof SzAbstractVo) {
            $columnName = ucfirst(strtolower($columnName));
            $func = "set{$columnName}";
            $vo->$func($value);
        }
    }

    /**
     * 玩家更改等级
     *
     * @param int $userId
     * @param int $exp
     * @throws SzException 30606
     * @return false
     */
    public function updatePlayerExp($userId, $exp)
    {
        UserService::get()->updateExp($userId, $exp);
        return true;
    }

    /**
     * add item for player
     *
     * @param int $userId
     * @param int $itemDefId
     * @param int $count
     * @return boolean
     */
    public function sendItem($userId, $itemDefId, $count)
    {
      //  $satrt_date =date("Y-m-d H:i:s",GameService::get()->getSysTime()) ;
      //  $actorId = ModulePrivilege::get()->checkLoginState();
        $items = array(19000003,19000001,10000001);
        if (in_array($itemDefId,$items)) {
            if ($itemDefId == 10000001) {
                $actionId = GameConst::ENTITY_ACTION_GET_MONEY;
            } else {
                $actionId = "7251".$itemDefId;
            }
            GameService::get()->handleEntity($userId, $actionId, $count, true);
          //  error_log('GM_sendItem---'.$satrt_date.'---'.$actorId.'---send---'.$userId.'---'.$itemDefId.'---'.$count."\r\n",3,$_ENV['LOG_ROOT'] . '/gm');
        } else {
            /**
             * @var ModuleItemVoList $itemList
             */
            $itemList = SzPersister::get()->getVoList($userId, ModuleItemConst::ORM_NAME_ITEM);
            ModuleItem::get()->addItemCount($userId, $count, $itemList, $itemDefId, null, array(), true, true);

            SzPersister::get()->setVoList($itemList);

           // error_log('GM_sendItem---'.$satrt_date.'---'.$actorId.'---send---'.$userId.'---'.$itemDefId.'---'.$count."\r\n",3,$_ENV['LOG_ROOT'] . '/gm');

            return true;
        }
    }

    /**
     * reduce item count
     *
     * @param int $userId
     * @param int $itemDefId
     * @param int $count
     * @return bool
     */
    public function reduceItem($userId, $itemDefId, $count)
    {
       // $satrt_date =date("Y-m-d H:i:s",GameService::get()->getSysTime()) ;
      //  $actorId = ModulePrivilege::get()->checkLoginState();
        $items = array(19000003,19000001,10000001);
        if (in_array($itemDefId,$items)) {
            if ($itemDefId == 10000001) {
                $actionId = GameConst::ENTITY_ACTION_CONSUME_MONEY;
            } else {
                $actionId = "7451".$itemDefId;
            }
            GameService::get()->handleEntity($userId, $actionId, $count, true);
           // error_log('GM_reduceItem---'.$satrt_date.'---'.$actorId.'---reduce---'.$userId.'---'.$itemDefId.'---'.$count."\r\n",3,$_ENV['LOG_ROOT'] . '/gm');

        } else {
            /**
             * @var ModuleItemVoList $itemList
             */
            $itemList = SzPersister::get()->getVoList($userId, ModuleItemConst::ORM_NAME_ITEM);

            ModuleItem::get()->reduceItemCountByDefId($userId, $itemDefId, $count, $itemList);
            SzPersister::get()->setVoList($itemList);

         //   error_log('GM_reduceItem---'.$satrt_date.'---'.$actorId.'---reduce---'.$userId.'---'.$itemDefId.'---'.$count."\r\n",3,$_ENV['LOG_ROOT'] . '/gm');
        }
        return true;
    }

    /**
     * 脚本处理
     *
     * @param int $type
     * @param string $password
     * @throws SzException 30600
     * @return boolean
     */
    public function handleScript($type, $password)
    {
        if ($password != ModuleGmConst::GM_PASSWORD) {
            throw new SzException(30600, null, ModuleGmConst::MODULE_NAME); // invalid $data
        }
        return false;
    }

    /**
     * 服务器状态变更
     *
     * @param int $handle
     * @param string $msg
     * @return boolean|array
     */
    public function handleServerStatus($handle, $msg)
    {
        switch ($handle) {
            case 1:
                //query
                return GameService::get()->serverStatus();
            case 2:
                //open
                return GameService::get()->openServer();
            case 3:
                //close
                $params["msg"] = $msg;
                return GameService::get()->closeServer($params);
            default:
                return false;
        }
    }

    /**
     * 更多游戏开关
     * @param $handle
     * @param $msg
     * @return boolean|array
     */
    public function handleMoreGameStatus($handle) {
        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        if ($handle == 1) {
            $status = $redisDb->get(GameConst::CACHE_KEY_MORE_GAME_STATUS);
            if (!$status) {
                $status = 0;
            }

        } elseif ($handle == 2) {
            $status = 1;
            $redisDb->set(GameConst::CACHE_KEY_MORE_GAME_STATUS,$status);
        } else {
            $status = 0;
            $redisDb->set(GameConst::CACHE_KEY_MORE_GAME_STATUS,$status);
        }
        
        return array(
            'server_state' => $status ? 'open' : 'close',
        );
    }

    /**
     * 全民热玩开关
     */
    public function handleHotPlayStatus($handle) {
        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        if ($handle == 1) {
            $status = $redisDb->get(GameConst::CACHE_KEY_HOT_PLAY_STATUS);
            if (!$status) {
                $status = 0;
            }

        } elseif ($handle == 2) {
            $status = 1;
            $redisDb->set(GameConst::CACHE_KEY_HOT_PLAY_STATUS,$status);
        } else {
            $status = 0;
            $redisDb->set(GameConst::CACHE_KEY_HOT_PLAY_STATUS,$status);
        }

        return array(
            'server_state' => $status ? 'open' : 'close',
        );
    }

    public function handleGmStatus($handle) {
        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        if ($handle == 1) {
            $status = $redisDb->get(GameConst::CACHE_KEY_GM_STATUS);
            if (!$status) {
                $status = 0;
            }

        } elseif ($handle == 2) {
            $status = 1;
            $redisDb->set(GameConst::CACHE_KEY_GM_STATUS ,$status);
        } else {
            $status = 0;
            $redisDb->set(GameConst::CACHE_KEY_GM_STATUS ,$status);
        }

        return array(
            'server_state' => $status ? 'open' : 'close',
        );
    }

    public function handleNoticeStatus($handle) {
        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        if ($handle == 1) {
            $status = $redisDb->get(GameConst::CACHE_KEY_NOTICE_STATUS);
            if (!$status) {
                $status = 0;
            }

        } elseif ($handle == 2) {
            $status = 1;
            $redisDb->set(GameConst::CACHE_KEY_NOTICE_STATUS ,$status);
        } else {
            $status = 0;
            $redisDb->set(GameConst::CACHE_KEY_NOTICE_STATUS ,$status);
        }

        return array(
            'server_state' => $status ? 'open' : 'close',
        );
    }

    public function handleShareStatus($handle) {
        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        if ($handle == 1) {
            $status = $redisDb->get(GameConst::CACHE_KEY_SHARE_STATUS);
            if (!$status) {
                $status = 0;
            }

        } elseif ($handle == 2) {
            $status = 1;
            $redisDb->set(GameConst::CACHE_KEY_SHARE_STATUS ,$status);
        } else {
            $status = 0;
            $redisDb->set(GameConst::CACHE_KEY_SHARE_STATUS ,$status);
        }

        return array(
            'server_state' => $status ? 'open' : 'close',
        );
    }

    public function handleOperationCache($handle, $cacheKey, $uId) {
        $uId = (int)$uId;
        $redisDb = null;
        if ($uId) {
            $redisDb = SzContextFactory::get()->getAppCache($uId);

            $key = $cacheKey.':'.$uId;
        } else {
            $redisDb = SzContextFactory::get()->getAppCache();
            $key = $cacheKey;
        }
        $data = array();
        if ($handle == 1) {
            $data = $redisDb->hGetAll($key);
        } else {
            $redisDb->delete($key);
        }
        return $data;
    }

    public function delete() {
        $time = date("Y-m-d",strtotime("-31 day"));
        $time = strtotime($time);
        $level = 9;
        $serversConfigs = SzConfig::get()->loadAppConfig('database', 'MySql');
        foreach ($serversConfigs as $serversConfig) {
            $instance = new SzMySqlDb($serversConfig);
            $data1 = $instance->select("select count(*) as c from `module_profile` where `lastLoginTime` < {$time} and `level` < {$level}");
            $j = intval($data1[0]['c'] / 500) + 1;
            for ($i=0;$i<$j;$i++) {
                $start = 0 + 500 * $i;
                $end = $start + 500;
                $list = $instance->select("select userId from `module_profile` where `lastLoginTime` < {$time} and `level` < {$level} limit {$start},{$end}");
                foreach ($list as $data) {
                    echo $data['userId']."\n";
//                    $this->deletePlayer($data['userId']);
                }
            }

        }
    }

    /**
     * 获取所有跑马灯
     * @return array
     */
    public function checkTextScroll($is_gm) {
        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        $redisTextScroll = $redisDb->hGetAll(GameConst::CACHE_KEY_TEXT_SCROLL);
        $results = array();
        $name = '';
        $start = 0;
        $end = 0;

        foreach ($redisTextScroll as $key=>$data){
            $temp = explode('&',$data);
            if (!empty($temp)){
                //时间操作
                if ($temp[0] == 2){
                    $start = strtotime(date('Y-m-d',time())) + $temp[1];
                    $end = strtotime(date('Y-m-d',time())) + $temp[2];
                }
                if ($temp[0] == 3){
                    $start = $temp[1];
                    $end = $temp[2];
                }
                //格式整理
                if ($is_gm){
                    if ($temp[0] == 1){
                        $name = '普通';
                    }
                    if ($temp[0] == 2){
                        $name = '每日';
                    }
                    if ($temp[0] == 3){
                        $name = '紧急';
                    }
                    $results[] = array(
                        'tid'   =>  $key,
                        'type'  =>  $name,
                        'start' =>  $start?date('Y年m月d日 h时i分s秒', $start):0,//Y-m-d h:i:s
                        'end'   =>  $end?date('Y年m月d日 h时i分s秒', $end):0,
                        'interval'=>$temp[3],
                        'content'=> $temp[4]
                    );
                }
                else{
                    $results[$temp[0]][] = array(
                        'tid'   =>  $key,
                        'start' =>  $start,
                        'end'   =>  $end,
                        'content'=> $temp[4],
                        'interval'=>$temp[3],
                    );
                }
            }
        }

        return array('textScroll' => $results);
    }

    /**
     * 新增跑马灯
     * @param $tid
     * @param $type
     * @param $time
     * @param $start
     * @param $end
     * @param $interval
     * @param $content
     * @throws SzException
     */
    public function insertTextScroll($tid, $type, $start, $end, $interval,$content){
        if ((empty($tid) || !is_numeric($tid) || $tid == null) ||
            (empty($type) || !is_numeric($type) || $type == null) ||
            (empty($content) || $content == null)
        ){
            throw new SzException(29032);
        }

        if ($type == 2){//每日固定时间播放
            if ((empty($start) || !is_numeric($start) || $start == null) ||
                (empty($end) || !is_numeric($end) || $end == null) ||
                (empty($interval) || !is_numeric($interval) || $interval == null)
            ){
                throw new SzException(29033,2);
            }
        }

        if ($type == 3){//紧急播报
            if ((empty($start) || !is_numeric($start)) ||
                (empty($end) || !is_numeric($end)) ||
                (empty($interval) || !is_numeric($interval) || $interval == null)
            ){
                throw new SzException(29033,3);
            }
        }

        if ($type == 2){
            if (empty($interval) || $interval == 0){
                $interval = 3;
            }
        }

        if ($type == 3){
            if (empty($interval) || $interval == 0) {
                $interval = 2;
            }
        }

        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        $redisTextScroll = $redisDb->hGet(GameConst::CACHE_KEY_TEXT_SCROLL,$tid);
        if ($redisTextScroll){
            throw new SzException(29034,$tid);
        }

        //hash
        $redisDb->hSet(GameConst::CACHE_KEY_TEXT_SCROLL,$tid,
            ($type?$type:1).'&'.
            ($start?$start:0).'&'.
            ($end?$end:0).'&'.
            $interval.'&'.
            $content);
    }

    /**
     * 删除跑马灯
     * @param $tid
     * @return bool
     */
    public function deleteTextScroll($tid){
        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        $redisTextScroll = $redisDb->hGet(GameConst::CACHE_KEY_TEXT_SCROLL,$tid);
        if ($redisTextScroll){
            $redisDb->hDel(GameConst::CACHE_KEY_TEXT_SCROLL,$tid);
        }else{
            return false;
        }
    }

//    /**
//     * 获取所有跑马灯
//     * @return array
//     * @throws SzException
//     */
//    public function checkTextScroll()
//    {
//        //获取跑马灯数据
//        $textScrollList = SzPersister::get()->getVoList(null, GameConst::ORM_NAME_TEXT_SCROLL);
//        $textScrolls = $textScrollList->toArray();
//        $results = array();
//
//        foreach ($textScrolls as $tid=>$data){
//            if (empty($data['type'])){
//                continue;
//            }
//            $results[$data['type']][]=  $data;
//        }
//
//        if (empty($results)){
//            return array();
//        }
//        else{
//            return $results;
//        }
//    }

//    /**
//     * 新增跑马灯
//     * @param $tid
//     * @param $content
//     * @param $type
//     * @param $time
//     * @param $start
//     * @param $end
//     * @return bool
//     * @throws SzException
//     */
//    public function insertTextScroll($tid, $type, $time, $start, $end, $content)
//    {
//        //获取跑马灯数据
//        if (empty($tid) || empty($content)){
//            throw new SzException(29031);//参数错误
//        }
//        $textScrollList = SzPersister::get()->getVoList(null, GameConst::ORM_NAME_TEXT_SCROLL);
//        $textScrolls = $textScrollList->toArray();
//        $is_create = false;
//
//        foreach ($textScrolls as $id=>$data){
//            if ($id == $tid){
//                $is_create = true;
//                break;
//            }
//        }
//        if ($is_create){
//            throw new SzException(29028);//该跑马灯已存在
//        }
//        else{
//            $textScroll = $textScrollList->getElement($tid,false);
//            if (!$textScroll) {
//                $textScroll = new TextScrollVo(
//                    $tid, // tid
//                    $type?$type:0, //type
//                    $time?$time:0, //time
//                    $start?$start:0, //start
//                    $end?$end:0,//end
//                    $content,//content
//                    true
//                );
//            }
//
//            if ($textScroll->isInsert() && !SzUtility::checkArrayKey($tid, $textScrollList->getList())) {
//                $textScrollList->addElement($textScroll);
//                $textScrollList->setElement($tid,$textScroll);
//            }
//            SzPersister::get()->setVoList($textScrollList);
//            return true;
//        }
//
//    }

//    /**
//     * 修改跑马灯
//     * @param $tid
//     * @param $content
//     * @param $time
//     * @param $start
//     * @param $end
//     * @return bool
//     * @throws SzException
//     */
//    public function updateTextScroll($tid, $content, $time, $start, $end)
//    {
//        /**
//         * @var TextScrollVo $textScroll
//         */
//        //获取跑马灯数据
//        $textScrollList = SzPersister::get()->getVoList(null, GameConst::ORM_NAME_TEXT_SCROLL);
//        $textScrolls = $textScrollList->toArray();
//        $is_create = false;
//
//        foreach ($textScrolls as $id=>$data){
//            if ($id == $tid){
//                $is_create = true;
//                break;
//            }
//        }
//
//        if (!$is_create){
//            throw new SzException(29031);//该跑马灯不存在
//        }
//        else{
//            $textScroll = $textScrollList->getElement($tid,false);
//            $textScroll->setTime($time);
//            $textScroll->setStart($start);
//            $textScroll->setEnd($end);
//            $textScroll->setContent($content);
//            $textScrollList->updateElement($tid,$textScroll);
//            SzPersister::get()->setVoList($textScrollList);
//            return true;
//        }
//    }
//
//    /**
//     * 删除跑马灯
//     * @param $tid
//     * @return bool
//     * @throws SzException
//     */
//    public function deleteTextScroll($tid)
//    {
//        //获取跑马灯数据
//        $textScrollList = SzPersister::get()->getVoList(null, GameConst::ORM_NAME_TEXT_SCROLL);
//        $textScrolls = $textScrollList->toArray();
//        $is_create = false;
//
//        foreach ($textScrolls as $id=>$data){
//            if ($id == $tid){
//                $is_create = true;
//                break;
//            }
//        }
//
//        if (!$is_create){
//            throw new SzException(29031);//该跑马灯不存在
//        }
//        else{
//            $textScrollList->deleteElement($tid);
//            SzPersister::get()->setVoList($textScrollList);
//
//            return true;
//        }
//    }
}
